home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / wemdemo4.zip / INFO / EDEBUG.1 (.txt) < prev    next >
GNU Info File  |  1994-09-21  |  49KB  |  842 lines

  1. This is Info file ../info/edebug, produced by Makeinfo-1.56 from the
  2. input file edebug.txi.
  3.    This file documents Edebug
  4.    This is edition 1.2 of the Edebug User Manual for edebug Version 2.6,
  5.    Copyright (C) 1991 Daniel LaLiberte
  6.    Permission is granted to make and distribute verbatim copies of this
  7. manual provided the copyright notice and this permission notice are
  8. preserved on all copies.
  9.    Permission is granted to copy and distribute modified versions of
  10. this manual under the conditions for verbatim copying, provided that
  11. the entire resulting derived work is distributed under the terms of a
  12. permission notice identical to this one.
  13.    Permission is granted to copy and distribute translations of this
  14. manual into another language, under the above conditions for modified
  15. versions, except that this permission notice may be stated in a
  16. translation approved by the Foundation.
  17. File: edebug,  Node: Top,  Next: Installation,  Up: (dir)
  18. Edebug
  19. ******
  20. * Menu:
  21. * Installation::        Installation
  22. * Using Edebug::        Using Edebug
  23. * Evaluating defuns::        Evaluating defuns
  24. * Edebug Modes::        Edebug Modes
  25. * Miscellaneous::        Miscellaneous
  26. * Breakpoints::            Breakpoints
  27. * Views::            Views
  28. * Evaluation::            Evaluation
  29. * Printing::            Printing
  30. * The Outside Context::        The Outside Context
  31. * Macro Calls::            Macro Calls
  32. * Options::            Options
  33. * Todo List::            Todo List
  34. * Index::            Index
  35.    Edebug is a source level debugger for GNU Emacs Lisp that provides
  36. the following features:
  37.    * Step through the evaluation of your functions and macros, stopping
  38.      before and after each expression, displaying the results of
  39.      expressions.
  40.    * Set conditional or unconditional breakpoints.
  41.    * Go until a breakpoint is reached, or ignore breakpoints.
  42.    * Trace slow or fast stopping briefly at each stop point, or each
  43.      breakpoint.
  44.    * Evaluate expressions as if outside of edebug.
  45.    * Automatically reevaluate a list of expressions and display their
  46.      results each time edebug updates the display.
  47.    * Output tracing info on function enter and exit.
  48.    * Catch errors normally caught by debug.
  49.    * Display backtrace without edebug calls.
  50.    * Interface with the `custom-print' package.
  51.    It isn't necessary to read all of this document, or even most of it,
  52. in order to make use of edebug.  You should minimally read sections
  53. Installation, Using Edebug, and Edebug Modes; the rest can be read as
  54. needed.
  55.    This manual assumes you are familiar with Emacs Lisp, as described
  56. in the GNU Emacs Lisp Reference Manual.  You might want to review the
  57. chapters on Evaluation and Debugging.
  58. File: edebug,  Node: Installation,  Next: Using Edebug,  Prev: Top,  Up: Top
  59. Installation
  60. ============
  61.    Put `edebug.el' in some directory in your `load-path' and
  62. byte-compile it.
  63.    Put the following forms in your `.emacs' file.
  64.      (define-key emacs-lisp-mode-map "\C-xx" 'edebug-defun)
  65.      (autoload 'edebug-defun "edebug")
  66.    If you wish to change the default edebug global command prefix,
  67. include the following.
  68.      (setq edebug-global-prefix "\C-xX") ; or whatever you want
  69. File: edebug,  Node: Using Edebug,  Next: Evaluating defuns,  Prev: Installation,  Up: Top
  70. Using Edebug
  71. ============
  72.    To use edebug you must be editing an Emacs Lisp buffer using
  73. `emacs-lisp-mode', or its equivalent, since the Emacs Lisp syntax table
  74. must be present.
  75.    The following commands are described in this section.
  76. `C-xx'
  77.      (`edebug-defun') Evaluates the function or macro at or after point
  78.      setting it up for use by edebug.  Unlike `eval-defun' it always
  79.      prints `edebug: NAME' in the minibuffer and a prefix argument has
  80.      a different effect as described below.  If a syntax error is
  81.      found, point is left at the error and mark is set to the original
  82.      point.
  83.      (`edebug-help') Display the help message for `edebug-mode'.
  84.      (`abort-recursive-edit') Abort the edebug recursive edit.  This
  85.      only aborts one level as opposed to all the way to the top level.
  86.      (`top-level') Exit all recursive editing levels to the top level
  87.      command loop.
  88.      (`edebug-previous-result') Redisplay the result of the previous
  89.      expression in the echo area.
  90.    To use edebug, simply evaluate a `defun' or `defmacro' with
  91. `edebug-defun' (`C-xx') when the point is in or before the definition.
  92. The next time your function or macro is called, edebug will be called.
  93. From now on, discussion about using edebug with functions includes
  94. macros, unless otherwise specified.  Like `eval-defun', `edebug-defun'
  95. evaluates function definitions, but adds edebug calls to the lambda
  96. expression.
  97.    To restore a function to normal operation after the definition has
  98. been evaluated with `edebug-defun', simply reevaluate it with one of the
  99. commands that evaluate definitions (e.g., `eval-defun' (`M-C-x'),
  100. `eval-current-buffer', or if the buffer is unchanged, `load-library').
  101. However, the behavior of most of these evaluating functions can also be
  102. modified by edebug, as described in *Note Evaluating defuns::.
  103.    Implementation note:  Recall that a `defun' is the source code
  104. definition of a function and evaluation of a definition puts the lambda
  105. expression for the function in the function cell of the symbol naming
  106. the function.  After evaluating a `defun' with `edebug-defun', the
  107. lambda expression stored in the function symbol's function cell
  108. contains a call to the function `edebug-enter' at the top level and
  109. individual calls to the function `edebug-before' and `edebug-after' for
  110. each expression that may be evaluated in the function.
  111.    When you call your function explicitly or via another function,
  112. edebug will be called, but it may or may not stop execution depending
  113. on what the current edebug mode is.  Some edebug modes only update the
  114. display to indicate the progress of the evaluation without stopping
  115. execution.  The default initial edebug mode is `step' which does stop
  116. execution.  The edebug modes are described in detail below (*note
  117. Edebug Modes::.).
  118.    Each time edebug updates the display to indicate the progress of the
  119. evaluation, the buffer that the function is defined in is displayed
  120. temporarily.  Also point is moved (temporarily) to the expression in the
  121. function about to be evaluated (or just evaluated) and an overlay arrow
  122. is displayed at the left end of the line containing point.  If the point
  123. is not visible in the window, the window start is changed
  124. (semi-permanently!) so that point is visible, while trying to display
  125. as much of the following code as possible.  See *Note The Outside
  126. Context:: for more details on how the Emacs display is affected by
  127. edebug.
  128.    In the example below, the definition of the `fac' function has been
  129. evaluated with `edebug-defun' (by positioning point within the
  130. definition and hitting `C-xx') and the expression `(fac 3)' has been
  131. evaluated.  The arrow on the first line indicates that edebug has been
  132. entered.  To indicate that you are stopped before the first expression,
  133. the cursor would be on the first left parenthesis of that line.
  134.      (defun fac (n)
  135.      =>(if (< 0 n)
  136.            (* n (fac (1- n)))
  137.          1))
  138.    When execution is stopped, you are "in edebug" in a recursive edit
  139. with point in the buffer defining the function, as described above.
  140. This buffer, called the "edebug buffer", is made read-only and the
  141. `edebug-mode' minor mode is activated.  Several commands are available
  142. in addition to the standard `emacs-lisp-mode' bindings.  Try the `?'
  143. command (`edebug-help') for a list of edebug commands.  From the edebug
  144. recursive edit, you are permitted to call functions that invoke edebug
  145. again recursively.  At any time in edebug, you can quit to the top
  146. level with `q' (`top-level)' or abort one recursive edit level with `a'
  147. (`abort-recursive-edit').
  148.    Places within a function that edebug may stop, called "stop points",
  149. are before and after expressions that are not self-evaluating, i.e. list
  150. forms and symbols.  However, edebug does not stop before symbols (i.e.,
  151. variables) unless `edebug-stop-before-symbols' is non-`nil', since it
  152. is not usually useful to do so.  When stopped after an expression,
  153. edebug displays the result of the expression in the minibuffer.  Use
  154. the `r' command (`edebug-previous-result') to see that result again.
  155. You can control the way in which expression results are printed by
  156. using the `custom-print' package (*note Printing::.).
  157.    Edebug knows about all the special forms, interactive forms with
  158. expressions, anonymous lambda expressions, and embedded `defun' or
  159. `defmacro' calls.  It cannot know what a macro will do with the
  160. arguments of a macro call so you must tell it; *note Macro Calls::. for
  161. the details.  You can use the same mechanism to tell edebug that some
  162. function arguments should be functions.
  163.    Continuing the example of the `fac' function, the user may step
  164. through the execution of the function (with SPC) stopping in edebug at
  165. the stop points which are marked with a period:
  166.      (defun fac (n)
  167.      =>.(if .(< 0 n.).
  168.            .(* n. .(fac (1- n.).).).
  169.          1).)
  170.    Whenever a function evaluated with `edebug-defun' is active, the
  171. Emacs debugger named by the variable `debugger' is set to
  172. `edebug-debug', so it is not necessary to set it yourself.  (Currently
  173. there is no option to turn off this feature.)  If an error occurs and
  174. `debug-on-error' is non-`nil', edebug will display the error and move
  175. point to the last known stop point.  This applies to quit signals too,
  176. if `debug-on-quit' is non-`nil'.  But in any case, if no function that
  177. was evaluated with `edebug-defun' is currently active, `debug' is run
  178. normally.  Note that you can also get a full backtrace inside of edebug
  179. (see *Note Miscellaneous::).
  180. File: edebug,  Node: Evaluating defuns,  Next: Edebug Modes,  Prev: Using Edebug,  Up: Top
  181. Evaluating defuns
  182. =================
  183.    There are a couple other ways to evaluate a `defun' for edebug
  184. besides calling `edebug-defun' directly.  The variable
  185. `edebug-all-defuns' affects the behavior of several commands defined by
  186. Emacs.  `eval-defun' (`M-C-x') is redefined by `edebug.el' to use
  187. `edebug-defun' if `edebug-all-defuns' is non-`nil', or alternatively,
  188. if you supply a prefix argument.  But if `edebug-all-defuns' is
  189. non-`nil' and you also supply a prefix argument, `edebug-defun' will
  190. not be used.  In other words, the prefix argument of `eval-defun'
  191. reverses the effect of `edebug-all-defuns'.  The default value of
  192. `edebug-all-defuns' is `nil'.  Call the function `edebug-all-defuns' to
  193. toggle the value of the variable `edebug-all-defuns'.
  194.    Note that this version of `eval-defun' evaluates whatever top level
  195. form it finds, as it normally does, but only `defun's (and `defmacro's)
  196. are evaluated with `edebug-defun'.
  197.    `eval-region' is redefined to use `edebug-defun' when evaluating
  198. `defun's (if `edebug-all-defuns' is non-`nil').  The prefix argument
  199. for `eval-region' has the normal behavior since it is used by other
  200. functions (including the standard functions `eval-defun',
  201. `eval-print-last-sexp', and `eval-last-sexp').  If an error occurs
  202. during the evaluation, point is left after the expression in error.
  203. Also, this `eval-region' does not use `narrow-to-region' to limit the
  204. scope of evaluation, and consequently there is a small difference in
  205. how white space is handled after an expression when the output is
  206. inserted in the buffer.
  207.    `eval-current-buffer' is redefined to use `eval-region', since the
  208. standard version does not, thus gaining all the benefits of the new
  209. `eval-region'.
  210.    Note that loading does not invoke `edebug-defun', since the load
  211. functions are subroutines that use the internal `eval-region' rather
  212. than the redefined one supplied by `edebug.el'.  This could be
  213. considered a feature since loading a file does not also visit the file
  214. which would be necessary if edebug were to be invoked on one of the
  215. functions defined in the file.
  216.    See *Note Evaluation:: for discussion of other evaluation functions
  217. available inside of edebug.
  218. File: edebug,  Node: Edebug Modes,  Next: Miscellaneous,  Prev: Evaluating defuns,  Up: Top
  219. Edebug Modes
  220. ============
  221.    While your function is being evaluated, edebug is in one of several
  222. modes.  The current mode is called the "edebug mode", not to be
  223. confused with major or minor modes.  The current edebug mode determines
  224. how edebug displays the progress of the evaluation, whether it stops at
  225. each stop point, or continues to the next breakpoint, for example.
  226.    Each time you enter edebug, you will be in the same mode you
  227. specified the previous time you were in edebug.  The exception is when
  228. edebug is first entered for each recursive edit level; then the mode is
  229. changed to the value in the global variable `edebug-initial-mode', which
  230. defaults to "step" mode.  In the case of a command where the
  231. `interactive' form has an expression argument, the expression is
  232. evaluated before the function is really entered, so the edebug mode
  233. defaults to `edebug-initial-mode' both for this expression and for the
  234. first expression in the function body.  (In fact, this repeated
  235. resetting to the initial mode also occurs each time your function is
  236. called non-recursively before returning to the command level which
  237. invoked the function.)
  238.    Below is a table of the keys which change the edebug mode.  For each
  239. key, the mode is set and the recursive edit is exited; what happens
  240. next depends on which mode you selected, which code your function
  241. executes, and whether a breakpoint is hit.  You can also set the edebug
  242. mode when edebug is not running (or in a non-edebug buffer) by hitting
  243. `C-xX' (default value of `edebug-global-prefix') followed by the same
  244. key as used inside of edebug.  Most of the other edebug commands are
  245. available in the same manner.
  246. `SPC'
  247.      (`edebug-step-through') Step mode stops at the next stop point
  248.      encountered.
  249.      (`edebug-trace') Trace mode pauses one second at each edebug stop
  250.      point.
  251.      (`edebug-Trace-fast') Trace with zero pause time at each stop
  252.      point.
  253.      (`edebug-continue') Continue after pausing for one second at each
  254.      breakpoint.
  255.      (`edebug-Continue-fast') Continue with zero pause time at each
  256.      breakpoint.
  257.      (`edebug-go') Go until a breakpoint.  *Note Breakpoints::.
  258.      (`edebug-Go-nonstop') Go non-stop ignoring breakpoints.  This is
  259.      the fastest way to execute code that has edebug calls in it, but
  260.      this mode of execution is still interruptible; see below.
  261.      (`edebug-stop') Stop executing at the first stop point encountered,
  262.      regardless of the mode.  This command does not change the mode and
  263.      does not continue execution; it is intended to be used to
  264.      interrupt execution.
  265.    To execute edebugged code more rapidly, use commands farther down in
  266. the list.  For example, Go-nonstop mode is alot faster that trace mode
  267. since it ignores breakpoints.  The continue modes do not stop at
  268. breakpoints, but merely pause at them.
  269.    While executing or tracing, you can interrupt the execution by
  270. hitting one of the edebug command characters, at which time the command
  271. is acted on.  For example, hitting SPC will stop execution at the first
  272. stop point because input is pending, but will then step to the next stop
  273. point.  Alternatively, `S' is bound to `edebug-stop' which does nothing
  274. but stop.  If your function happens to read input, a character you hit
  275. intending to interrupt execution may be read by the function instead,
  276. so be careful in the neighborhood of the read call.  Also see the
  277. discussion of errors and quit signals in *Note Using Edebug::.
  278.    Keyboard macros invoked within edebug will not work across edebug
  279. calls, so you must enter each edebug command separately.  (It doesn't
  280. seem worth it to save and restore keyboard macro definitions and
  281. executions between calls to edebug in such a way that it doesn't affect
  282. any outside command processing, and it may not be possible in any case.)
  283. File: edebug,  Node: Miscellaneous,  Next: Breakpoints,  Prev: Edebug Modes,  Up: Top
  284. Miscellaneous
  285. =============
  286.    Some miscellaneous commands are described here.
  287.      (`edebug-forward-sexp') Proceed from the current point to the sexp
  288.      found by first doing `forward-sexp' and then switching to go mode.
  289.      If a prefix argument is supplied, do `forward-sexp' that many
  290.      times.  If there are not enough sexps for `forward-sexp', call
  291.      `edebug-step-out' instead.  Be careful that the sexp found by
  292.      `forward-exp' will be executed; this will not always be the case in
  293.      a `condition-case', for example.  A temporary breakpoint is set at
  294.      the stop point, so it will be used and cleared whenever execution
  295.      reaches it.  See *Note Breakpoints:: for the details on
  296.      breakpoints.
  297.      Notice that we do the `forward-sexp' starting at the current point
  298.      rather than the stop point, thus providing more flexibility.  If
  299.      you want to start the search at the stop point, first do
  300.      `edebug-where' (`w').
  301.      (`edebug-step-out') Proceed from the current point to the end of
  302.      the containing sexp.  If the containing sexp is the top level
  303.      defun, go to the end of the last sexp instead, or if that is the
  304.      same point, then step out of the function.  Therefore this command
  305.      does not exit the currently executing function unless you are
  306.      positioned after the last sexp of the function.
  307.      Like `edebug-forward-sexp', this command switches to go mode to get
  308.      to the containing sexp.  The only situation in which the
  309.      containing sexp will not be reached by edebug is if a non-local
  310.      exit by-passes it.
  311.      (`edebug-step-in') Step into the function about to be called.  Use
  312.      this command before any of the arguments of the function call are
  313.      evaluated since otherwise it will be too late.  One side effect of
  314.      using `edebug-step-in' is that the next time the stepped-into
  315.      function is called, edebug will be called there as well.  (I may
  316.      try to fix this in the future.)
  317.      (`edebug-goto-here') Proceed to the stop point near the current
  318.      point.  A temporary breakpoint is used.  See *Note Breakpoints::
  319.      for details on how the stop point is found.
  320.      (`edebug-backtrace') A `debug'-like backtrace is displayed.  All
  321.      calls to edebug functions are removed to clean up the display.
  322.      This backtrace does not function like the standard backtrace so
  323.      you cannot specify which frames to stop at, etc. - but it is
  324.      better than nothing.  The backtrace buffer is killed automatically
  325.      when you continue execution.
  326. File: edebug,  Node: Breakpoints,  Next: Views,  Prev: Miscellaneous,  Up: Top
  327. Breakpoints
  328. ===========
  329.    The purpose of "breakpoints" is to let you specify significant
  330. places in your code where you would like edebug to stop or pause
  331. execution.  Breakpoints may be set at any stop points as defined in
  332. *Note Using Edebug::, even before symbols.  Edebug will stop or pause
  333. at a breakpoint except when the edebug mode is Go-nonstop.  For setting
  334. and unsetting breakpoints, the stop point that is affected is at or
  335. after the current point.  The following commands are related to
  336. breakpoints:
  337.      (`edebug-set-breakpoint') Set a breakpoint at the stop point at or
  338.      after the current point.  With prefix-arg, the breakpoint is
  339.      temporary.
  340.      (`edebug-unset-breakpoint') Unset or clear a breakpoint at the
  341.      stop point at or after the current point.
  342.      (`edebug-set-conditional-breakpoint') Set a conditional
  343.      breakpoint.  You are asked for the conditional expression.  With
  344.      prefix-arg, the breakpoint is temporary.
  345.      (`edebug-next-breakpoint') Move point to the next breakpoint in
  346.      the current function definition.
  347.    While in edebug, you can set a breakpoint with `b'
  348. (`edebug-set-breakpoint') and unset (or clear) it with `u'
  349. (`edebug-unset-breakpoint').  First move point to a position at or
  350. before the desired edebug stop point, then hit the key to change the
  351. breakpoint.  Unsetting a breakpoint that has not been set does nothing.
  352.    Reevaluating the defun with `edebug-defun' clears all breakpoints in
  353. the function.  (Let me know if you would like breakpoints preserved; I
  354. could use marks for breakpoints instead of relying on the offsets from
  355. the beginning of the defun.)
  356.    A "conditional breakpoint" is set with `x'
  357. (`edebug-set-conditional-breakpoint').  When you set a conditional
  358. breakpoint you will be asked for an expression which is evaluated each
  359. time the breakpoint is reached.  Edebug will only stop at a conditional
  360. breakpoint if the condition evaluates to non-`nil'.  But conditional
  361. breakpoints are not even checked if the edebug mode is Go-nonstop.
  362.    For both conditional and unconditional breakpoints, the breakpoint
  363. can be made into a "temporary breakpoint" if you give a prefix arg to
  364. the command.  After breaking at a temporary breakpoint, it is
  365. automatically cleared.
  366.    To find out where your breakpoints are, use the `B'
  367. (`edebug-next-breakpoint') command which moves point to the next
  368. breakpoint in the function following point, or to the first breakpoint
  369. if there are no following breakpoints.  (Note that this command does not
  370. continue execution - it just moves the point.)
  371. File: edebug,  Node: Views,  Next: Evaluation,  Prev: Breakpoints,  Up: Top
  372. Views
  373. =====
  374.    If the function you are debugging modifies the Emacs window
  375. environment, you may wish to check the "outside window configuration"
  376. as it was before edebug was called, since edebug itself also modifies
  377. the window environment (see *Note Outside Window Configuration:: for
  378. how edebug tries to restore it). The following commands relate to views
  379. in general.
  380.      (`edebug-view-outside') View the outside window configuration.
  381.      (`edebug-bounce-point') Bounce to the point in the outside current
  382.      buffer, and return after one second.
  383.      (`edebug-where') Move point back to the current stop point.
  384.      (`edebug-toggle-save-windows') Toggle the `edebug-save-windows'
  385.      variable.  Each time you toggle it, the inside and outside window
  386.      configurations become the same as the current configuration.  By
  387.      turning this off and on again, edebug thereafter restores the
  388.      outside window configuration to the current configuration.
  389.    You can view the outside window configuration with `v'
  390. (`edebug-view-outside') or bounce to the current point in the current
  391. buffer with `p' (`edebug-bounce-point'), even if it is not normally
  392. displayed.  After moving point or changing buffers, you may wish to pop
  393. back to the stop point with `w' (`edebug-where') from an edebug window
  394. or `C-xXw' in any window.
  395. File: edebug,  Node: Evaluation,  Next: Printing,  Prev: Views,  Up: Top
  396. Evaluation
  397. ==========
  398.    This section describes commands related to the explicit and automatic
  399. evaluation of expressions in edebug.  Edebug attempts to make such
  400. evaluations while inside of edebug appear that they are occuring
  401. outside of edebug, as if edebug had not been invoked.  Almost everything
  402. about the outside context is restored (*note The Outside Context::. for
  403. the details).  But `M-ESC' (`eval-expression') still evaluates
  404. expressions normally (in the current context) since that is occasionally
  405. needed.  Also supported is an evaluation list window where expressions
  406. may be evaluated interactively or automatically.
  407.    You can control the way in which expression results are printed by
  408. using the `custom-print' package (*note Printing::.).
  409.      (`edebug-eval-expression') Evaluates an expression in the "outside
  410.      context" of your function, rather than in the edebug context as
  411.      `M-ESC' does.  (These commands are therefore consistent with the
  412.      same commands in the standard debugger.)
  413. `C-xC-e'
  414.      (`edebug-eval-last-sexp') Like `eval-last-sexp' except in the
  415.      outside context.
  416.      (`edebug-visit-eval-list') Jump to an evaluation list window in
  417.      which several other commands apply, described below.  The
  418.      evaluation list is reevaluated each time the edebug display is
  419.      updated (including tracing) and the results are displayed in a
  420.      temporary buffer `*edebug*'.
  421.    The following commands apply to the evaluation list which is
  422. displayed in the `*edebug*' buffer.  All the `lisp-interaction-mode'
  423. commands are also available.
  424. `LFD'
  425.      (`edebug-eval-print-last-sexp') Similar to `eval-print-last-sexp'
  426.      but in the outside context.
  427. `C-xC-e'
  428.      (`edebug-eval-last-sexp') Similar to `eval-last-sexp' but in the
  429.      outside context.
  430. `C-cC-u'
  431.      (`edebug-update-eval-list') Build a new evaluation list from the
  432.      first expression of each group, reevaluate and redisplay.  Groups
  433.      are separated by a line starting with a comment.
  434. `C-cC-d'
  435.      (`edebug-delete-eval-item') Delete the evaluation list group that
  436.      point is in.
  437. `C-cC-w'
  438.      (`edebug-where') Jump back to the edebug buffer at the current stop
  439.      point.
  440.    In the evaluation list window, type in expressions and evaluate them
  441. with `LFD' (`edebug-eval-print-last-sexp') or `C-xC-e'
  442. (`edebug-eval-last-sexp'), just as you would for lisp interaction mode
  443. but the evaluation is done in the outside context.  (Note:
  444. `eval-region' is not redefined to evaluate in the outside context; it
  445. is only redefined to use `edebug-defun' when it encounters a defun -
  446. see *Note Evaluating defuns::.)
  447.    The expressions you enter interactively, and their results, will be
  448. lost when you continue execution of your function unless you add them
  449. to the evaluation list.  To add any number of expressions to the
  450. evaluation list use `C-cC-u' (`edebug-update-eval-list').  This builds a
  451. new list from the first expression of each "group", where groups are
  452. separated by a line starting with a comment.
  453.    When the evaluation list is redisplayed, each expression is displayed
  454. followed by the result of evaluating it, and a comment line.  If an
  455. error occurs during an evaluation, the error message is displayed in a
  456. string as if it were the result.  Therefore expressions that use
  457. undefined variables will not interrupt your debugging.  Here is an
  458. example of what the evaluation list window looks like after several
  459. expressions have been added to it.
  460.      (current-buffer)
  461.      #<buffer *scratch*>
  462.      ;---------------------------------------------------------------
  463.      (point-min)
  464.      1
  465.      ;---------------------------------------------------------------
  466.      (point-max)
  467.      2
  468.      ;---------------------------------------------------------------
  469.      edebug-outside-point-max
  470.      "Symbol's value as variable is void: edebug-outside-point-max"
  471.      ;---------------------------------------------------------------
  472.      (recursion-depth)
  473.      0
  474.      ;---------------------------------------------------------------
  475.      this-command
  476.      eval-last-sexp
  477.      ;---------------------------------------------------------------
  478.    You can delete the group that point is positioned in with `C-cC-d'
  479. (`edebug-delete-eval-item'), or use normal editing commands to modify
  480. the text as much as you want (e.g. delete-region).  Be sure to update
  481. the evaluation list with `C-cC-u' before you continue evaluation of
  482. your function or quit to the top level, unless you want your changes to
  483. be lost.  Also be sure to separate each "group" with a comment before
  484. updating, otherwise the wrong expressions may end up in the list.
  485.    You can return to the source code buffer (the edebug buffer) with
  486. `C-cC-w' which is equivalent to `C-xXw'.  The `*edebug*' buffer is
  487. killed when you continue execution of your function, and recreated next
  488. time it is needed.
  489.    If you are concerned with exactly how the evaluation is done, you may
  490. need to know that the evaluation of expressions occurs in one of two
  491. slightly different outside contexts.  If the evaluation list is
  492. non-empty when edebug is entered, the context used to evaluate it is
  493. closest to the true outside context since nothing much has changed when
  494. the evaluation is done.  However, when you evaluate expressions within
  495. edebug using the above described interactive commands or when you update
  496. the evaluation list, as much of the outside context is restored as
  497. possible, but not everything (*note The Outside Context::.).  One way to
  498. observe the difference is to look at the `recursion-depth'.
  499. File: edebug,  Node: Printing,  Next: The Outside Context,  Prev: Evaluation,  Up: Top
  500. Printing
  501. ========
  502.    If the results of your expressions contain circular references to
  503. other parts of the same structure, the standard Emacs print subroutines
  504. may fail to print with an error, "Apparently circular structure being
  505. printed".  If you only use cdr circular lists (where cdrs of lists point
  506. back; what is the right term here?), you can limit the length of
  507. printing with `print-length' and edebug does this for you when printing
  508. out the previous result.  But car circular lists and circular vectors
  509. generate the above mentioned untrappable error in Emacs version 18.
  510. Version 19 will support `print-level', but it is often useful to get a
  511. better print representation of circular structures.
  512.    To handle printing of structures more generally, you can use the
  513. `custom-print' package which supports `print-level', `print-circle',
  514. and further customizations via `custom-print-list' and
  515. `custom-print-vector'.  See the documentation strings of these
  516. variables for more details.  There are two main ways to use this
  517. package.  First, you may replace `prin1', `princ', and some subroutines
  518. that use them by calling `install-custom-print-funcs' so that any use
  519. of these functions in lisp code will be affected.  Second, you could
  520. call the custom routines directly, thus only affecting the printing
  521. that requires them.  Edebug uses the second method, as described next.
  522.    To load the package and activate custom printing only for edebug,
  523. simply use the command `edebug-install-custom-print-funcs'.  This sets
  524. the function cells of `edebug-prin1', `edebug-print',
  525. `edebug-prin1-to-string', and `edebug-format' to the symbol names of
  526. the corresponding custom versions.  Therefore, any changes you make to
  527. the custom functions or to the variables controlling custom printing
  528. take effect immediately.  Notice you still need to set `print-level' or
  529. `print-circle'.  To restore the standard print functions, use
  530. `edebug-reset-print-funcs'.
  531. File: edebug,  Node: The Outside Context,  Next: Macro Calls,  Prev: Printing,  Up: Top
  532. The Outside Context
  533. ===================
  534.    This section is useful for those who need to know more precisely what
  535. edebug is doing that might affect editing and the context of expression
  536. evaluation.  For the most part, edebug operates transparently and there
  537. should be no apparent difference running with edebug, except for
  538. debugging itself.  If you find any variation with what is described
  539. here, please let me know.
  540.    An important distinction is made between the "outside context" which
  541. exists before edebug is invoked, and the "inside context" which exists
  542. while edebug is active.  Most of the outside context is saved and
  543. restored each time you enter and exit from edebug.  In addition, most
  544. evaluations you do within edebug (see *Note Evaluation::) occur in the
  545. same outside context which is temporarily restored for the evaluation.
  546.    Described in this section are the aspects of the outside context that
  547. are saved and restored including things as diverse as window
  548. configurations, current buffer status, and variable values.  These
  549. aspects are divided into three sections, corresponding to the degree to
  550. which edebug has affected the outside context.  The first section,
  551. immediately following this, is for those things that are affected any
  552. time edebug is called even if the display is not updated.  The second
  553. section is for when edebug must update the display.  The third section
  554. is for when edebug stops execution and enters a recursive edit.
  555. Finally, the few unavoidable side effects of using edebug are described.
  556. * Menu:
  557. * Just Checking::        Just Checking
  558. * Outside Window Configuration::  Outside Window Configuration
  559. * Recursive Edit::        Recursive Edit
  560. * Side Effects::        Side Effects
  561. File: edebug,  Node: Just Checking,  Next: Outside Window Configuration,  Prev: The Outside Context,  Up: The Outside Context
  562. Just Checking
  563. -------------
  564.    The following are saved and restored when edebug is called even if
  565. the display is not updated.  One reason there is anything at all to
  566. save and restore is that the call to `edebug-enter' must remain active
  567. while your function is active, and this impacts the Lisp stack.  The
  568. other reason is that execution may be interrupted at any time unless the
  569. edebug mode is Go-nonstop, but an executing keyboard macro should not
  570. interrupt execution.
  571.    * `max-lisp-eval-depth' and `max-specpdl-size' are both incremented
  572.      for each `edebug-enter' call so that your code should not be
  573.      impacted by edebug frames on the stack.  I believe they are
  574.      incremented too much currently, but that is better than not enough.
  575.    * A keyboard macro executed outside of edebug should not affect the
  576.      operation of edebug.  Other input will be caught by edebug,
  577.      however, interrupting execution as described in *Note Edebug
  578.      Modes::.  If you are defining a keyboard macro when edebug is
  579.      entered, all your command input will be included in the macro, but
  580.      this is not much use since the macro will not be executed the same
  581.      way.  I don't know if it is safe to suspend definition of a
  582.      kbd-macro, or if it is useful to allow execution of a macro to
  583.      continue into edebug.  Let me know if you figure this out.
  584. File: edebug,  Node: Outside Window Configuration,  Next: Recursive Edit,  Prev: Just Checking,  Up: The Outside Context
  585. Outside Window Configuration
  586. ----------------------------
  587.    One important aspect of the outside context is the "outside window
  588. configuration".  A full description of window configurations may be
  589. found in the GNU Emacs Lisp Reference Manual.  If you are running
  590. `epoch', the concept of a window configuration is generalized to
  591. include the set of current screens, though if you create or destroy
  592. screens while in edebug, this effect will not be reversed.
  593.    When you exit from edebug (each time you continue execution, in
  594. fact), the window configuration outside of edebug is restored to what
  595. it was before edebug was entered.  But since Emacs delays screen update
  596. until needed, if you then reenter edebug before a screen update is
  597. required, it will appear that you never left; that is, the outside
  598. window configuration will not be displayed even though it was in
  599. effect.  If your function completes normally, the outside window
  600. configuration will finally be displayed when you return to the command
  601. level, or any time a screen update is forced by some other means (e.g.
  602. `sit-for').
  603.    The window configuration, as defined by Emacs, does not include which
  604. buffer is current or where point and mark are in the current buffer, but
  605. edebug saves and restores these also.  Note that the outside window
  606. configuration restored by edebug may not be fully consistent with the
  607. real outside context since the selected window may not yet have been
  608. displayed but edebug may have forced screen update.
  609.    If the display needs to be updated by edebug, e.g. a trace mode is
  610. active, the following are saved and restored.  However, if an error or
  611. quit signal occurs, some of these are intensionally not restored for
  612. user convenience.
  613.    * The point of the edebug buffer (the one containing the function
  614.      definition) is saved and restored only if the outside current
  615.      buffer is the same as the edebug buffer.  (The point is also not
  616.      restored on error or quit.)
  617.    * The outside window configuration, as described above, is saved and
  618.      restored if `edebug-save-windows' is non-`nil'.  These are not
  619.      restored on error or quit, but the outside selected window is
  620.      reselected even on error or quit in case a `save-excursion' is
  621.      active.  The window start for the edebug buffer is not restored,
  622.      however, so that the next time it is displayed, the window start
  623.      will be in the same position it was last time.
  624.    * The current buffer, and point and mark in the current buffer are
  625.      normally saved and restored even if the current buffer is the same
  626.      as the edebug buffer.  They are not restored on error or quit, but
  627.      in that event the current buffer will be changed to the outside
  628.      selected window's buffer when you return to the command loop, as
  629.      it normally is.
  630.    * The points of all displayed buffers are saved and restored if
  631.      `edebug-save-displayed-buffer-points' is non-`nil'.  See the
  632.      description of that variable for more details.
  633.    * The `overlay-arrow-position' and `overlay-arrow-string' are saved
  634.      and restored.  Since edebug uses these variables, saving and
  635.      restoring also permits recursive use of edebug, or other uses of
  636.      the overlay arrow by the outside context.
  637.    * `cursor-in-echo-area' is locally bound to `nil' so that the cursor
  638.      shows up in the window.
  639. File: edebug,  Node: Recursive Edit,  Next: Side Effects,  Prev: Outside Window Configuration,  Up: The Outside Context
  640. Recursive Edit
  641. --------------
  642.    If edebug stops execution and enters a recursive-edit, the following
  643. additional things are saved and restored.
  644.    * The read-only status of the edebug buffer, since edebug changes it
  645.      to read-only.
  646.    * The current match data, for whichever buffer was current.  Note
  647.      that Emacs 18.56 partially fixed a bug in `match-data' so that it
  648.      works better with `string-search'.
  649.    * The local keymap of the edebug buffer.
  650.    * `last-command', `this-command', `last-command-char', and
  651.      `last-input-char'.  Commands within the recursive edit will not
  652.      affect these variables outside of edebug.
  653.      But note that the result of `(this-command-keys)' and the value of
  654.      `unread-command-char' cannot be protected, as described below.
  655.    * `standard-output' and `standard-input'.  `recursive-edit' locally
  656.      binds these to the default `nil' values (correct??).
  657. File: edebug,  Node: Side Effects,  Prev: Recursive Edit,  Up: The Outside Context
  658. Side Effects
  659. ------------
  660.    Many other things may be changed by the user explicitly while in the
  661. edebug recursive edit if they are not protected against change as
  662. described above, and this may be considered a feature in most cases.
  663. However, some possibly undesirable side effects of using edebug remain,
  664. most of which are unavoidable:
  665.    * Changes to the text of buffers are not undone.
  666.    * Lisp stack usage is increased, but the limits,
  667.      `max-lisp-eval-depth' and `max-specpdl-size', are also increased
  668.      proportionally.
  669.    * The key sequence returned by `this-command-keys' is changed by
  670.      executing commands within edebug and there appears to be no way to
  671.      reset the key sequence from Lisp.
  672.    * `unread-command-char' is not protected because its value appears
  673.      to be used even before the command loop is entered by a recursive
  674.      edit.  Thus storing a char in `unread-command-char' always causes
  675.      it to be used for a command in edebug.  I don't know of a
  676.      work-around.
  677.    * Complex commands executed while in edebug are added to the
  678.      `command-history'.  This is probably recoverable, but I havent
  679.      investigated it yet.
  680.    * When you update the evaluation window, the recursion depth will
  681.      appear one deeper than the outside context recursion depth.
  682.    * Horizontal scrolling of the edebug buffer is not recovered.  This
  683.      is probably recoverable, but I havent investigated it yet.
  684.    * If you discover others, please let me know.
  685. File: edebug,  Node: Macro Calls,  Next: Options,  Prev: The Outside Context,  Up: Top
  686. Macro Calls
  687. ===========
  688.    This section describes a mechanism you may use to tell edebug how
  689. the arguments of macro calls should be evaluated.  The same mechanism
  690. may be used for special forms and some function calls.
  691.    To edebug your macro calls, you must specify how the arguments may be
  692. evaluated.  In the general case, not all macro arguments will be
  693. evaluated.  But if it so happens that all your macro arguments are
  694. "evaluatable" (i.e. they may eventually be evaluated either explicitly
  695. in the macro body or when the resulting expansion is evaluated), then
  696. you can set the `edebug-eval-macro-args' option to non-`nil'.  On the
  697. other hand, if you don't want any of your macro arguments to be
  698. evaluated by edebug then you can ensure they will not be wrapped in
  699. edebug calls by setting `edebug-eval-macro-args' to `nil' (the default).
  700.    In the more likely case that some macro arguments are to remain
  701. unevaluated (e.g. a symbol) and some may be evaluated, you can specify
  702. an `edebug-form-spec' for each macro.  Implementation note: edebug uses
  703. `edebug-form-spec's for special forms and some function calls as well
  704. as macro calls.  You can do the same, but there is not really much
  705. point, except for functions that take function arguments.
  706.    Use the macro `def-edebug-form-spec' to define a specification for a
  707. function or macro which is stored in the `edebug-form-spec' property of
  708. the symbol naming the function or macro.  The first argument is the
  709. symbol name and the second argument is the specification which may be
  710. one of five kinds of values.  First, if a specification for a symbol is
  711. `nil' or undefined, then depending on the value of
  712. `edebug-eval-macro-args', all the arguments will be treated as
  713. evaluatable (if it's non-`nil') or unevaluatable (if it's `nil').
  714.    If the specification is a quoted function (symbol or lambda
  715. expression), then this function is called to process the arguments of
  716. the calling form.
  717.    As a convenience, `def-edebug-form-spec' may be given `t' or `0' as
  718. its second argument.  If it is `t', then all arguments are treated as
  719. evaluatable; if it is `0' (not `nil'), then all arguments are treated
  720. as unevaluateable.  Implementation note: these values are actually
  721. converted by `def-edebug-form-spec' to the functions `edebug-forms' and
  722. `edebug-sexps' respectively.
  723.    Finally, if the `edebug-form-spec' is a list, then the elements of
  724. the list describe the types of the arguments of a calling form.  The
  725. list is processed left to right, in the same order as the arguments of
  726. the calling form, and the elements constrain the types of corresponding
  727. arguments and specify whether they may be evaluated.  Each element may
  728. be one of the following:
  729. `symbolp'
  730.      An unevaluated symbol.
  731. `integerp'
  732.      An unevaluated number.
  733. `stringp'
  734.      An unevaluated string.
  735. `vectorp'
  736.      An unevaluated vector.
  737. `atom'
  738.      An unevaluated number, string, symbol, or vector.
  739. `sexp'
  740.      An unevaluated sexp (atom or list); the argument may be `nil' or
  741.      `()' but it must not be missing.
  742. `form'
  743.      An evaluated sexp.
  744. `function'
  745.      A function argument may be a quoted (using quote or function)
  746.      symbol or lambda expression or a form (that should evaluate to a
  747.      function or lambda expression).  The body of an anonymous function
  748.      will be treated as evaluateable.
  749. `OTHER'
  750.      Any other symbol should be the name of a function; this function is
  751.      called on the argument as a predicate, and an error is signaled if
  752.      the predicate fails.  You could use this to check whether a
  753.      literal is of a certain custom type.
  754. `(...)'
  755.      A sublist of the same format as the top level, processed
  756.      recursively.  The actual argument must be a list as well.  Special
  757.      case: if the car of the element is quote, the actual argument must
  758.      match the quoted sexp, usually a symbol (see example of `for'
  759.      macro below).
  760. `[...]'
  761.      A sublist of the same format as the top level, processed
  762.      recursively.  It is processed like `(...)' except the matched
  763.      arguments are inserted in-line into the arguments matched by the
  764.      containing list, somewhat analogous to `@,' in backquoted
  765.      expressions.  This may be used for grouping to build complex
  766.      elements out of the primitives provided.
  767. `&optional'
  768.      All following elements in the specification list at this level may
  769.      or may not match arguments; as soon as one does not match,
  770.      processing of the specification list terminates.  To get only one
  771.      specification item to be optional, use `[...]'.
  772. `&rest'
  773.      All following elements in the specification list at this level are
  774.      repeated in order zero or more times.  Allowing more than one
  775.      `&rest' element is an extension of the normal meaning of &rest.
  776.      All the `&rest' elements need not be used in every repetition,
  777.      however.  Only one `&rest' may appear at the same level of a
  778.      specification list, and `&rest' must not be followed by
  779.      `&optional'.  To specify that only some types arguments are to be
  780.      repeated until failure, followed by some other types of arguments,
  781.      use `[...]'.
  782. `&or'
  783.      Each of the following elements in the specification list at this
  784.      level are alternatives, processed left to right until one
  785.      succeeds.  To group two or more list elements as one alternative,
  786.      bracket them in `[...]'.  Only one `&or' may appear in a list, and
  787.      it may not be followed by `&optional' or `&rest'.  One of the
  788.      alternatives must match, unless the `&or' is preceeded by
  789.      `&optional' or `&rest'.
  790.    If a failure to match occurs, this does not necessarily mean a syntax
  791. error will be signalled; instead, "backtracking" will take place until
  792. all alternatives have been exhausted.  `&optional' elements need not
  793. match at all of course, but evenually every element of the argument
  794. list must be matched or an error will be signalled.  Non-optional
  795. elements in the specification unused when the argument list has been
  796. completely matched will also cause backtracking, or ultimately a syntax
  797. error.
  798.    The combination of backtracking, `&optional', `&rest', `&or', and
  799. `[...]' for grouping provides the equivalent of regular expressions.
  800. The `(...)' lists require balanced parentheses, which is the only
  801. context free (finite state with stack) construct supported.  Dotted
  802. pair notation is not yet supported, but let me know if you need it.
  803.    I am considering writing a compiler for `edebug-form-spec' list
  804. forms that would generate elisp code to process arguments the same way
  805. `edebug-interpret-form-spec' now does it but alot faster.  Suggestions
  806. appreciated.
  807.    Here are some examples of using `edebug-form-spec'.  A `let' form
  808. looks like: `(let (BINDINGS ...) FORMS ...)', where each of the
  809. BINDINGS is either a SYMBOL or `(SYMBOL VALUE-FORM)'.  The
  810. `edebug-form-spec' for a `let' form is defined as follows:
  811.      (def-edebug-form-spec let
  812.        '((&rest
  813.          &or symbolp (symbolp &optional form))
  814.         &rest form))
  815.    A `for' loop macro is defined in the GNU Emacs Lisp Reference Manual
  816. (reference needed), and `cl.el' defines `case' and `do' macros.  Here
  817. are their edebug-form-specs.
  818.      (def-edebug-form-spec for
  819.        '(symbolp 'from form 'to form 'do &rest form))
  820.      
  821.      (def-edebug-form-spec case
  822.        '(form &rest (sexp form)))
  823.      
  824.      (def-edebug-form-spec do
  825.        '((&rest &or symbolp (symbolp &optional form form))
  826.          (form &rest form)
  827.          &rest body))
  828.    Finally, the functions `mapcar', `mapconcat', `mapatoms', `apply',
  829. and `funcall' all take function arguments, and edebug defines
  830. specifications like the following one for `apply'.
  831.      (def-edebug-form-spec apply '(function &rest form))
  832.    Note that backquote (``') is a macro that results in an expression
  833. that is not necessarily evaluated.  It is often used to simplify the
  834. definition of a macro where the result of the macro call is evaluated,
  835. but edebug does not know when this is the case.  So do not be surprised
  836. when you cannot step through your backquoted code.  23 On the other
  837. hand, one could wrap the backquoted expression in a special function,
  838. say `edebug-`', which would mean that the result of the backquote form
  839. will, in fact, be evaluated.  Then edebug could wrap evaluateable
  840. expressions within the backquoted expression in edebug calls.  Is it
  841. worth it?
  842.